package com.jinniulive.platform.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jinniulive.platform.R;
import com.jinniulive.platform.bean.VideoListInfo;

import java.util.List;

/**
 * Created by Administrater on 2016/12/8.
 */

public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.VideoHolder> {
    List<VideoListInfo.VideoDataBean.MvlstBean> mData;
    Context mContext;
    public interface OnItemClickListener{
        void addOnClickListener(View view,int position);
    }
    private OnItemClickListener mListener;
    public void setOnItemClickListener(OnItemClickListener listener){
        mListener=listener;
    }

    public VideoListAdapter(Context context) {
        mContext = context;
    }

    public void setmData(List<VideoListInfo.VideoDataBean.MvlstBean> data) {
        if (data != null) {
            mData = data;
            notifyDataSetChanged();
        }
    }

    @Override
    public VideoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new VideoHolder(LayoutInflater.from(mContext).inflate(R.layout.item_video_content, parent, false));
    }

    @Override
    public void onBindViewHolder(VideoHolder holder, int position) {
        VideoListInfo.VideoDataBean.MvlstBean mvlstBean = mData.get(position);
        Glide.with(mContext).load(mvlstBean.getVideoPreview()).centerCrop().into(holder.ivLogo);
        holder.tvLecture.setText("讲师：" + mvlstBean.getVideoLecture());
        holder.createDate.setText(mvlstBean.getCreatedate());
        holder.tvVideoTitle.setText("视频:"+mvlstBean.getVideoTitle());
        holder.tvVideoDesc.setText(mvlstBean.getVideoIntro());
    }

    @Override
    public int getItemCount() {
        return mData!=null?mData.size():0;
    }

    class VideoHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private ImageView ivLogo;
        private TextView tvLecture;
        private TextView createDate;
        private TextView tvVideoTitle;
        private TextView tvVideoDesc;

        VideoHolder(View itemView) {
            super(itemView);
            ivLogo = (ImageView) itemView.findViewById(R.id.iv_video_logo);
            tvLecture = (TextView) itemView.findViewById(R.id.tv_video_lecture);
            createDate = (TextView) itemView.findViewById(R.id.tv_video_createDate);
            tvVideoTitle = (TextView) itemView.findViewById(R.id.tv_video_title);
            tvVideoDesc = (TextView) itemView.findViewById(R.id.tv_video_content);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View view) {
            int position=getPosition();
            if(mListener!=null){
                mListener.addOnClickListener(itemView,position);
            }
        }
    }
}
